// 用户管理模块接口
import request from '@/utils/request'

enum API {
  ALLUSER_URL = '/admin/acl/user/',
  ADDUSER_URL = '/admin/acl/user/save',
  UPDATEUSER_URL = '/admin/acl/user/update',
  ALLROLE_URL = '/admin/acl/user/toAssign/',
  ASSIGNROLE_URL = '/admin/acl/user/doAssignRole',
  DELETEUSER_URL = '/admin/acl/user/remove/',
  DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
}
export const reqUserInfo = (page: number, limit: number, username: string) =>
  request.get<any>(API.ALLUSER_URL + `${page}/${limit}?username=${username}`)

export const reqAddorUpdateUser = (data: any) => {
  if (data.id) {
    return request.put(API.UPDATEUSER_URL, data)
  } else {
    return request.post(API.ADDUSER_URL, data)
  }
}

export const reqAllRole = (userId) => request.get(API.ALLROLE_URL + userId)

export const reqAssignRole = (data) => request.post(API.ASSIGNROLE_URL, data)

export const reqDeleteUser = (id) => request.delete(API.DELETEUSER_URL + id)

export const reqDeleteAllUser = (idList) =>
  request.delete(API.DELETEALLUSER_URL, { data: idList })
